package com.lytoyo.neihanduanzi.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * Package:com.lytoyo.neihanduanzi.config
 *
 * @ClassName:ElasticsearchConfig
 * @Create:2025/4/2 15:12
 **/
@Configuration
@Slf4j
public class ElasticsearchConfig {
    @Value("${Elasticsearch.hostname}")
    private String hostname;

    @Value("${Elasticsearch.port}")
    private int port;

    @Bean
    public ElasticsearchClient elasticsearchClient(){
        RestClient restClient = RestClient.builder(new HttpHost(hostname, port)).build();
        RestClientTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
        ElasticsearchClient client = new ElasticsearchClient(transport);
        return client;
    }
}
